

function [rno, sno, rnb,snb, rm, sbm] = Solve_mbank(psim,psiw,alpha,k,Nb,Nn,Nm,qn,qb,eta,rhoo,rhob,sow,sbw,rb)
%% set up the solution to the model

%%% household preference shock grid and transition matrix 
MaxIterations=10000;
tol = 10^(-9);
rm_initial = 1.87;
rnb = [];
diff = 1000;
iter = 0;

while diff>tol && iter<=MaxIterations  
        iter = iter+1;
        [rno,sno,rnb,snb] =  Solve_local_financed(psim,psiw,alpha,k,Nb,Nn,Nm,qn,qb,eta,rhoo,rhob,sow,sbw,rb,rm_initial);
        sbm =  exp(-alpha*rm_initial+qb)/(1+Nb*exp(-alpha*rb+qb)+Nm*exp(-alpha*rm_initial+qb)+Nn*sow*exp(-alpha*rno+qn)+Nn*sbw*Nb*exp(-alpha*rnb+qn));
        rm = psim+1/(alpha*(1-sbm));
        diff = abs(rm-rm_initial);
        rm_initial = rm;
  

end 
end

